#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        vector<int> v;
        if (nums.size() == 1) {
            if (nums[0] == k)return 1;
            else return 0;
        }
        v.reserve(20010);
        int size = nums.size();
        int ans = 0;
        v[0] = 0;
        for (int i = 1; i <= size; i++) {
            v[i] = v[i - 1] + nums[i - 1];
        }
        for (int i = 0; i <= size; i++) {
            for (int j = i + 1; j <= size; j++) {
                if (v[j] - v[i] == k)ans++;
            }
        }
        return ans;
    }
};